import {
  DrawerForm,
  ProFormInstance,
  ProFormSegmented,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Input, Space, Tabs } from 'antd';
const { Search } = Input;
import React, { useRef, useState } from 'react';
import { dyCpsSearchStore } from '../service';

export type FormValueType = {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
} & Partial<API.RuleListItem>;

export type UpdateFormProps = {
  onCancel: (flag?: boolean, formVals?: FormValueType) => void;
  onSubmit: (values: FormValueType) => Promise<void>;
  updateModalVisible: boolean;
  values: Partial<API.RuleListItem>;
};

const UpdateFormDy: React.FC<UpdateFormProps> = (props) => {
  const formRef = useRef<ProFormInstance>();
  const [updateType, setUpdateType] = useState<any>('');
  return (
    <DrawerForm
      title="新建店铺"
      width="620px"
      formRef={formRef}
      visible={props.updateModalVisible}
      onVisibleChange={(val) => {
        if (!val) {
          props.onCancel();
        }
       
      }}
      onFinish={async (val) => {
        props.onSubmit({ ...val });
      }}
    >
      
     
      <ProFormText
        width="md"
        name="rate"
        label="佣金比例"
        tooltip="最长为 24 位"
        placeholder="请输入佣金比例"
        rules={[{ required: true, message: '佣金比例不能为空!' }]}
      />
      <ProFormSegmented
        name="upType"
        label="选择跟单方式"
        onChange={(val)=>{
          setUpdateType(val);
          console.log(updateType)

        }}
        valueEnum={{
          excel: '上传excel',
          order: '批量订单号',
        }}
      />
      {updateType === "excel" ? 
      <ProFormUploadDragger
        max={1}
        fieldProps={{
          name: 'file',
          onChange: (info) => {
            const { status, response } = info.file;
            if (status === 'done') {
              if (response?.code == 'SUCCESS') {
                console.log(response.data);
                // handlePageData(response?.data);
              }
            }
          },
        }}
        label=""
        action="/api/uploadDyFileDiff"
        name="dragger"
      /> : 
      <ProFormTextArea
        width="md"
        name="orders"
        label="订单号"
        tooltip="最长为 11 位"
        placeholder="请输入订单号,用逗号或者回车换行分割"
        rules={[{ required: true, message: '订单称不能为空!' }]}
      />
    }
    </DrawerForm>
  );
};

export default UpdateFormDy;
